#include "xgate_cfg.h"
/*===================== GLOBAL VARIABLES DECLARATION ============================*/

/*======================== FUNCTION DEFINITIONS =================================*/

/*********************************************************************************
*	Name: XGATE_Init      
*	Type: void                                                                    
*	Parameters: void                                                          
*	Description: Make Xgate initializaion routine              
**********************************************************************************/
void XGATE_Init( void  )
{
	/* Initialize the XGATE vector block and the XGVBR register */    
    XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);    
    
    /* Access to configuration data registers for interrupts */ 
	ROUTE_INTERRUPT(SOFTWARETRIGGER0_VEC, 0x81);
   	/* enable XGATE mode and interrupts */
	XGMCTL= 0xFBC1; /* XGE | XGFRZ | XGIE */     
}
/*********************************************************************************
*	Name: XGATE_SW_TRIGGER_X      
*	Type: void                                                                    
*	Parameters: TrggerNum (uint8_t) the numer of trigger that will be used
				TriggerMask (uint8_t) the mas of the trigger that will be used.                                                          
*	Description: Make a software interrupt from the S12 core                
**********************************************************************************/

void XGATE_SW_TRIGGER(uint8_t TriggerNum, uint8_t TriggerMask){
	uint16_t temp = 0x0000u;
	
	if ((TriggerNum< 8) && (TriggerMask < 2))
	{
		temp = 	(uint16_t)  ( ( (uint16_t)( ( 1 << TriggerNum ) << 8) ) | 
							 	((uint16_t)( TriggerMask << TriggerNum	) ));
		XGSWT = 	temp;
	}
}
